import React from 'react'
import ReactDOM from 'react-dom'
import App from '@/App'
import { configureReporter, perfReport, ADAPTER_APP_JS_BRIDGE_SA } from '@tiyafe/hawkeye';
import '@/assets/scss/reset.scss'

import lz from '@lizhife/lz-jssdk'
import { ENV } from '@/config/constant'

import '@/plugins/svg-sprite.plugin'

if (ENV === 'dev' || window.location.hash.indexOf('vconsole') >= 0) {
  let VConsole = require('vconsole/dist/vconsole.min.js')
  new VConsole()
}

// 对JSBridge 二次封装
lz.Ready = function (fun = () => {}) {
  this.isApp ? this.ready(fun) : fun()
}

lz.toast = function (text = '') {
  this.isApp ? this.showPrompt({ type: 0, msg: text }) : console.info('toast: ' + text)
}

// 将 JSBridge 丢入 window

window.lz = lz
lz.config({
  // signMethod: "post",
  apiList: [
    'getToken',
    'toAction',
    'getAppInfo',
    'traceReport',
    'getSessionUserId',
    'getSessionUser',
    'closeWebView',
    'startRecordVoice',
    'stopRecordVoice',
    'playUrl',
    'stopPlayUrl',
    'saveImage',
    'shareImage',
    'shareUrl',
    'showPrompt',
  ],
  eventList: ['viewLifeCycleStatus', 'playUrlStatus'],
})

ReactDOM.render(<App />, document.getElementById('root'))

window.lz.ready(() => {
  configureReporter(ADAPTER_APP_JS_BRIDGE_SA);
  perfReport({ eventName: 'FE_PERFORMANCE_MANUAL', project: 'halloween-act' });
  console.info('Register perf track...');
});

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
// serviceWorker.register();
